<template>
    <div>
        标题：{{list.title}}
        内容：{{list.content}}        

        <van-field  v-model="form.comment" type='textarea' placrholder='请输入内容' cols=6 />
        <van-button color="linear-gradient(to right, #ff6034,#7232dd)" @click="add">
                添加评论
        </van-button> 
        <br>
        <br>
        <table>
            <tr>
                <td>用户</td>
                <td>内容</td>
            </tr>
            <tr v-for="i in content">
                <td>{{i.username}}</td>
                <td>{{i.comment}}</td>
            </tr>
        </table>
        {{userid}}
    </div>
</template>

<script>
    export default {
        data(){
            return{
                id:this.$route.query.id,
                userid:localStorage.getItem('userid'),
                form:{aid:this.$route.query.id,userid:localStorage.getItem('userid')},
                list:[],
                content:[],
                
            }
        },
        methods:{
            add(){
                if(this.form.userid){
                    this.$axios.post('article/comment',this.form).then(res=>{
                    if(res.data.code==200){
                        alert('评论成功')
                        this.get_content()
                    }
                })
                }else{
                    this.$router.push('clogin')
                }
                
        },
        get_list(){
            this.$axios.get('article/login?id='+this.id).then(res=>{
                this.list = res.data.list
            })
        },
       get_content(){
            this.$axios.get('article/comment?id='+this.id).then(res=>{
                this.content = res.data.list
            })
        }
    },
    mounted(){
        this.get_list()
        this.get_content()
    }
    }
</script>

<style scoped>

</style>